package com.jingdinajichi.subject.common.entity;

import lombok.Getter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author zwy
 * @version 1.0
 * @description: PageResult
 * @date 2025/7/16 17:53
 */
@Getter
public class PageResult<T>
{
    private Integer pageNum = 1;
    private Integer pageSize = 20;
    private Integer total = 0;
    private Integer totalPages = 0;
    private List<T> result = new ArrayList<>() ;
    private Integer start = 1;
    private Integer end = 0;

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public void setRecords(List<T> result){
        this.result = result;
    }
    public void setTotal(Integer total){
        this.total = total;
        if(this.pageSize > 0){
            this.totalPages = (total/this.pageSize) + (total%this.pageSize == 0 ? 0 : 1);
        }else{
            this.totalPages = 0;
        }
        this.start = (this.pageSize > 0 ? this.pageNum - 1 : 0) * this.pageSize + 1;
        this.end = this.start  - 1 + this.pageSize * (this.pageNum > 0 ? 1 : 0);
    }


    @Override
    public String toString() {
        return "PageResult{" +
                "pageNum=" + pageNum +
                ", pageSize=" + pageSize +
                ", total=" + total +
                ", totalPages=" + totalPages +
                ", result=" + result +
                ", start=" + start +
                ", end=" + end +
                '}';
    }
    // 添加初始化 result 为可变列表的方法

}
